Create Project: springboot_deserialize_requestparameters (add Spring Boot Starters from the table)
Create Package: DTO (inside main package)
– Create Class: PersonDTO.java (inside package controllers)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
PersonDTO.java
package com.ivoronline.springboot_deserialize_requestparameters.DTO;
public class PersonDTO {
//PROPERTIES
public String name;
public Integer age;
//SETTERS (used for deserialization)
public void setName(String name) { this.name = name; }
public void setAge (Integer age ) { this.age = age; }
}
MyController.java
package com.ivoronline.springboot_deserialize_requestparameters.controllers;
import com.ivoronline.springboot_deserialize_requestparameters.DTO.PersonDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello(PersonDTO personDTO) {
return "Hello " + personDTO.name;
}
}